# 抛出异常 raise

class MyException(Exception):
    def __init__(self, name):
        print("hahahaha")
        self.name = name

    def getError(self):
        return "错误消息是:{}".format(self.name)


def register():
    username = input("输入用户名")

    if len(username) < 6:
        raise MyException("用户名不能小于6位")
    else:
        print("输入的用户名是:", username)


try:
    register()
except MyException as err:
    print(err.getError())
    print("注册失败")
else:
    print("注册成功")
